package com.example.essingwaldconfig.config;

import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.engine.EngineConfig;
import cn.smallbun.screw.core.engine.EngineFileType;
import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.process.ProcessConfig;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Data;

import javax.sql.DataSource;
import java.util.Arrays;
import java.util.List;

@Data
public class ShouldAnswerWithTrue {

    private String driverClassName = "com.mysql.cj.jdbc.Driver";

    // 数据源配置
    private String jdbcUrl = "jdbc:mysql://128.0.0.1//demo";
    private String username = "root";
    private String password = "root";

    private String propertyName = "useInformationSchema";

    private String propertyValue = "true";

    private Integer minimumIdle = 2 ;

    private Integer maximumPoolSize = 5 ;

    //生成文件路径
    private String fileOutputDir = "...";

    //打开目录
    private Boolean openOutputDir = true;

    //文件类型
    private EngineFileType fileType = EngineFileType.WORD;

    //忽略表(多表用","分割)
    private String tableName = "";
    List<String> ignoreTableName = Arrays.asList(tableName.split(","));

    //忽略表前缀
    List <String> ignorePrefix ;

    //忽略表后缀
    List <String> ignoreSuffix ;




    public HikariConfig getHikariConfig (){
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName(driverClassName);
        hikariConfig.setJdbcUrl(jdbcUrl);
        hikariConfig.setUsername(username);
        hikariConfig.setPassword(password);
        //设置可以获取tables remarks信息
        hikariConfig.addDataSourceProperty(propertyName,propertyValue);
        hikariConfig.setMinimumIdle(minimumIdle);
        hikariConfig.setMaximumPoolSize(maximumPoolSize);
        return hikariConfig;
    }

    public EngineConfig getEngineConfig (){
        //生成配置
        EngineConfig engineConfig = EngineConfig.builder()
                //生成文件路径
                .fileOutputDir(fileOutputDir)
                //打开目录
                .openOutputDir(openOutputDir)
                //文件类型
                .fileType(fileType)
                //生成模板实现
                .produceType(EngineTemplateType.freemarker).build();
        return engineConfig;
    }

    public ProcessConfig getProcessConfig(){
        ProcessConfig processConfig = ProcessConfig.builder()
                //忽略表名
                .ignoreTableName(ignoreTableName)
                //忽略表前缀
                .ignoreTablePrefix(ignorePrefix)
                //忽略表后缀
                .ignoreTableSuffix(ignoreSuffix).build();
        return processConfig;
    }

    DataSource dataSource = new HikariDataSource(getHikariConfig());

    public Configuration getConfiguration(){
        Configuration config = Configuration.builder()
                //版本
                .version("1.0.0")
                //描述
                .description("数据库设计文档生成")
                //数据源
                .dataSource(dataSource)
                //生成配置
                .engineConfig(getEngineConfig())
                //生成配置
                .produceConfig(getProcessConfig()).build();
        return config;
    }


}
